package com.sztest.jayjun.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.sztest.jayjun.MyApplication;
import com.sztest.jayjun.R;
import com.sztest.jayjun.utils.LogUtils;

import androidx.annotation.Nullable;

/*
 *  @项目名：  jayjun
 *  @包名：    com.sztest.jayjun.view
 *  @文件名:   NumView
 *  @创建者:   okmin
 *  @创建时间:  2022/6/30 10:53
 *  @描述：    TODO
 */
public class NumView extends LinearLayout {

    private int mMaxNum=-1;
    private int mCurNum;

    public NumView(Context context) {
        super(context);
        init();
    }

    public NumView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public NumView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public NumView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }

    ImageView mMaxBai;
    ImageView mMaxShi;
    ImageView mMaxGe;

    ImageView mXG;


    ImageView mCurBai;
    ImageView mCurShi;
    ImageView mCurGe;
    View mLine;
    View mNum;
    void init() {
        View.inflate(getContext(), R.layout.view_num, this);
        mMaxBai = findViewById(R.id.iv_max_bai);
        mMaxShi = findViewById(R.id.iv_max_shi);
        mMaxGe = findViewById(R.id.iv_max_ge);

        mCurBai = findViewById(R.id.iv_cur_bai);
        mCurShi = findViewById(R.id.iv_cur_shi);
        mCurGe = findViewById(R.id.iv_cur_ge);

        mXG=findViewById(R.id.iv_xg);

        mLine= findViewById(R.id.ll_line);
        mNum= findViewById(R.id.ll_num);
    }

    public void setCurNum(int curNum){
        mCurNum = curNum;
        int bai=curNum/100;
        int shi=curNum/10%10;
        int ge=curNum%10;
            mCurBai.setVisibility(bai!=0?VISIBLE:GONE);

            mCurShi.setVisibility(bai!=0?VISIBLE:(shi!=0?VISIBLE:GONE));

        mCurBai.setImageResource(getid(bai));
        mCurShi.setImageResource(getid(shi));
        mCurGe.setImageResource(getid(ge));
    }

    public int getMaxNum(){
        return mMaxNum;
    }

    public void setMaxNum(int maxNum){
//        LogUtils.e("maxNum="+maxNum);
        mMaxNum = maxNum;
        if (mMaxNum==-1) {

            mMaxBai.setVisibility(GONE);
            mMaxShi.setVisibility(GONE);
            mMaxGe.setVisibility(GONE);

            mXG.setVisibility(GONE);
            mLine.setVisibility(VISIBLE);
            mNum.setVisibility(GONE);
            return;
        }else {
            mNum.setVisibility(VISIBLE);
            mLine.setVisibility(GONE);
            mMaxGe.setVisibility(VISIBLE);
            mXG.setVisibility(VISIBLE);
        }

        int bai=maxNum/100;
        int shi=maxNum/10%10;
        int ge=maxNum%10;

            mMaxBai.setVisibility(bai!=0?VISIBLE:GONE);

            mMaxShi.setVisibility(bai!=0?VISIBLE:(shi!=0?VISIBLE:GONE));

        mMaxBai.setImageResource(getid(bai));
        mMaxShi.setImageResource(getid(shi));
        mMaxGe.setImageResource(getid(ge));
//        LogUtils.e("bai="+bai+"=shi="+shi+"=ge="+ge);
    }

    public void setMaxNumOnly(int maxNum){
        mMaxNum = maxNum;
    }

    public int getid(int level) {
//        LogUtils.e("等级"+level);
        int voiceResId=getResources().getIdentifier("icon_shuzi_"+level, "drawable", MyApplication.getInstance().getPackageName());
        return voiceResId;
    }

}
